const path = require('path');
const { name, version } = require('./package.json');

const mode = process.env.NODE_ENV.trim();
const debug = mode !== 'production';

let filename = name + '.min.js';
let sourceMapFilename = name + '.min.js.map';
if (debug) {
    filename = name + '.js';
    sourceMapFilename = name + '.js.map';
}

module.exports = {
    mode: mode,
    devtool: 'cheap-module-source-map',
    entry: path.resolve(__dirname, 'src/index.js'),
    output: {
        path: path.resolve(__dirname, 'lib', version),
        filename: filename,
        sourceMapFilename: sourceMapFilename,
        library: 'axios',
        libraryTarget: 'umd'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                include: path.resolve(__dirname, 'src'),
                use: [
                    {
                        loader: 'babel-loader'
                    },
                    {
                        loader: 'eslint-loader',
                        options: {
                            formatter: require('eslint-formatter-friendly'),
                            fix: true
                        }
                    }
                ]
            }
        ]
    }
};
